//
//  SettingViewController.m
//  EPBPro
//
//  Created by wucha on 2018/7/2.
//  Copyright © 2018年 fc. All rights reserved.
//

#import "SettingViewController.h"
#import "ModifyPasswordViewController.h"
#import "HttpLoginAction.h"
#import "AppDelegate.h"

@interface SettingViewController ()
@property (nonatomic,strong) NSArray *listArray;

@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.titleName = @"设置";
    self.listArray = @[@"密码修改"];
    self.tableView.separatorStyle = 0;
    self.tableView.tableFooterView = [self getFooterView];
}

-(UIView*)getFooterView{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100)];
    
    UIButton *button = [UIButton new];
    button.backgroundColor = DefaultBlueColor;
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    [button setTitle:@"退出登录" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(logoutAction:) forControlEvents:UIControlEventTouchUpInside];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [view addSubview:button];
    button.sd_layout.leftSpaceToView(view, 20).bottomSpaceToView(view, 0).rightSpaceToView(view, 20).heightIs(40);
    return view;
}

-(void)logoutAction:(id)sender{
    [BlockAlertView showAlertWithTitle:@"确定退出?" message:@"" alertViewStyle:UIAlertViewStyleDefault block:^(id clickView, NSInteger index) {
        if (index == 1) {
            [self showWaitingViewWithMessage:@"退出中..." style:WaitingViewShowStyleFullSelfView];
            [HttpLoginAction postLogOut:^(id result, NSError *error) {
                [self dismissWaitingView];
                if (!error) {
                    [[FileOperator defaultOperator] deleteUserInfo];
                    AppDelegate *appdelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
                    [appdelegate toLogin];
//                    [self.navigationController popViewControllerAnimated:NO];
//                    [[NSNotificationCenter defaultCenter] postNotificationName:@"ChangeIndex" object:@"mine"];
                }else{
                    [self showMessage:error.domain autoDissmissAfterDelay:0];
                }
            }];
            
        }
    } cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return self.listArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.selectionStyle = 0;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    // Configure the cell...
    cell.textLabel.text = self.listArray[indexPath.row];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ModifyPasswordViewController *modifyPasswordViewController = [[ModifyPasswordViewController alloc] init];
    [self.navigationController pushViewController:modifyPasswordViewController animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
